package com.koron.css2.serviceManage.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.baseConfig.bean.PubReceiptBean;
import com.koron.css2.baseConfig.mapper.PubReceiptMapper;
import com.koron.css2.baseConfig.queryBean.PubReceiptQueryBean;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.util.Constant;
import com.koron.util.JsonUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

public class ReceiptQuery implements ServerInterface {

	private static Logger logger = LogManager.getLogger(ReceiptQuery.class);
	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {

	MessageBean<PubReceiptBean> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", PubReceiptBean.class);
		try {
			PubReceiptMapper mapper = factory.getMapper(PubReceiptMapper.class);
			PubReceiptQueryBean bean = JsonUtils.objectToPojo(req.getData(), PubReceiptQueryBean.class);
			PubReceiptBean beanForReturn = mapper.selectById(bean.getReceiptId());
			info.setCode(Constant.MESSAGE_INT_SUCCESS);
			info.setDescription("success");
			info.setData(beanForReturn);
		} catch (Exception e) {
			info.setCode(Constant.MESSAGE_DBFAIL);
			info.setDescription("数据库异常");
			logger.error("数据库异常",e);
			factory.close(false);
		}
		return info;
	}

}
